<template>
  <div class="image-marker-tooltip">tooltip</div>
</template>

<script>
export default {
  name: 'MImageMarkerTooltip',

  inject: ['mImageMarker'],
  props: {
    formatter: {
      type: [String, Function],
      default: '',
    },
  },
  data() {
    return {}
  },
  created() {
    if (this.mImageMarker.$options.name !== 'MImageMarker') {
      console.error('MImageMarkerTooltip parent must be MImageMarker')
    }
    console.log(this.mImageMarker)
    console.log(this.mImageMarker.$options.name)
  },

  methods: {
    hide() {
      console.log('hide')
    },
    show(annotation) {
      console.log('show')
    },

    ShowTip(message, x, y, tipType = 'tip') {
      if (this.detailsDialogOpen) return
      // if(this.markType === 10) return;

      this.detailTooltip.x = x
      this.detailTooltip.y = y

      let attrs = message.split(';')
      let _values
      let pre = ''
      const typeName = attrs[0].split(':')[0]
      if (this.selectDictLabel(this.attributeNames, typeName + '_a1_2d')) pre = typeName + '_'
      try {
        let jsonObject = JSON.parse(this.selectDictLabel(this.attributeNames, 'labelName'))
        _values = jsonObject.values[typeName]
      } catch (e) {
        console.debug(e)
      }
      if (_values == null || _values == undefined || _values == '') _values = typeName
      if (tipType === 'tip') message = '类型：' + _values
      else message = tipType + _values
      message += '<br>'
      let _d = attrs[0].split(':')[1]
      for (let i = 1; i <= 8; i++) {
        if (attrs[i] && attrs[i] != null && attrs[i] != '' && attrs[i] != 'null') {
          try {
            let jsonObject = JSON.parse(this.selectDictLabel(this.attributeNames, pre + 'a' + i + '_' + _d + 'd'))
            let _values = jsonObject.values[attrs[i]]
            if (_values == null || _values == undefined || _values == '') _values = attrs[i]
            message += jsonObject.typeDesc + ': ' + _values + '&nbsp<br>'
          } catch {
            message += attrs[i]
          }
        }
      }
      for (let j = 9; j <= 17; j++) {
        let i = j - 8
        if (attrs[j] && attrs[j] != null && attrs[j] != '' && attrs[j] != 'null') {
          try {
            let jsonObject = JSON.parse(this.selectDictLabel(this.attributeNames, pre + 'b' + i + '_' + _d + 'd'))
            let _values = jsonObject.values[attrs[j]]
            if (_values == null || _values == undefined || _values == '') _values = attrs[j]
            message += jsonObject.typeDesc + ': ' + _values + '&nbsp<br>'
          } catch {
            message += attrs[j]
          }
        }
      }
      if (
        this.selectDictLabel(this.attributeNames, 'show3dSize') &&
        this.selectDictLabel(this.attributeNames, 'show3dSize') === 'true'
      ) {
        message += attrs[attrs.length - 1]
      }
      let headerHtml =
        "<div style='font-size:12px; color: #fec443; font-weight: bold; font-family: MicrosoftYaHei;'>" +
        message +
        '</div>'
      let effectHtml = "<div style='font-size:12px;margin-top:3px;' >" + '</div>'
      this.tooltipBody = headerHtml + effectHtml
      this.detailTooltip.show = true
    },
  },
}
</script>

<style lang="scss" scoped>
.image-marker-tooltip {
  position: absolute;
  display: none;
}

.special_focus_toolTip {
  z-index: 999;
  position: absolute;
  display: none;
  width: 180px;
  height: 240px;
  border-style: solid;
  transition: left 0.4s cubic-bezier(0.23, 1, 0.32, 1), top 0.4s cubic-bezier(0.23, 1, 0.32, 1);
  background-color: rgba(50, 50, 50, 0.701961);
  border-width: 0px;
  border-color: #333333;
  border-radius: 4px;
  color: #ffffff;
  font-style: normal;
  font-variant: normal;
  font-weight: normal;
  font-stretch: normal;
  font-size: 14px;
  font-family: 'Microsoft YaHei';
  line-height: 21px;
  padding: 10px 10px;
  pointer-events: none;
}
</style>
